//
//  E7StageScene.cpp
//  E7_ENGINE
//
//  Created by cc on 12-2-29.
//  Copyright (c) 2012年 PalmGame. All rights reserved.
//

#include "E7StageScene.h"

#include "E7GameManager.h"

CE7StageScene::CE7StageScene()
{
}

CE7StageScene::~CE7StageScene()
{
}

// 循环.
void CE7StageScene::step(float dt)
{
    m_fTotalTime += dt ;
    
    if (!m_pStageLayer->Loop())
    {
        Stop() ;
        return ;
    }
}

void CE7StageScene::Start()
{
//    printf("enter stage scene - s\n") ;
    
    if (S_START == m_eStep)
    {
        return ;
    }
    
    m_eStep = S_START ;
    m_fTotalTime = ZERO_FLOAT ;
    m_bIsVisible = true ;

    m_pBackSprite = new CE7Sprite() ;
    m_pBackSprite->Init("back_stage.png") ;
    addChild(m_pBackSprite) ;

    m_pStageLayer = new CE7StageLayer() ;
    addChild(m_pStageLayer) ;
    
    schedule(schedule_selector(CE7StageScene::step)) ;
    
//    printf("enter stage scene - e\n") ;
}

void CE7StageScene::Stop()
{
    if (S_START != m_eStep)
    {
        return ;
    }
    
    m_eStep = S_STOP ;
    
    unscheduleAllSelectors() ;
    removeAllChildrenWithCleanup(false) ; // cleanup flag.
    
    SAFE_RELEASE(m_pBackSprite) ;
    SAFE_RELEASE(m_pStageLayer) ;
    
    m_fTotalTime = INVALID_FLOAT ;
    m_bIsVisible = false ;
    
    g_pGameManager->ChangeSceneState(SS_GAME) ;
//    printf("change to single game scene\n") ;
}

